package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class Demo9 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();){
connection.setAutoCommit(false);
String sql="delete from user where id=? ";
PreparedStatement ps = connection.prepareStatement(sql);
ps.setInt(1,2);
int num = ps.executeUpdate();
if(num>0){
    connection.commit();
    System.out.println("删除成功");
}else {
    connection.rollback();
    System.out.println("删除失败");
}
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
